#ifndef LAPOSTE_ON_A_TOUS_A_Y_GAGHER_H_
#define LAPOSTE_ON_A_TOUS_A_Y_GAGHER_H_

#include <map>
#include <string>
#include <list>

#include "irrlicht.h"
#include "Message.h"

class Entity;
class Map;

/*!
	This class is used to dispatch the messages to receivers entities. All these methods are protected because just the base Entity class and the Map need the PostOffice.
	All these methode are static too, no need of instance here. That's also why the constructor and destructor are private.
*/
class PostOffice
{
	friend class Entity;
	friend class Map;
	friend class Message;

	private:
	/*! Constructor. Unused, but private to forbid instance creation. */
	PostOffice();
	/*! Destructor. Unused since no instances are created. */
	virtual ~PostOffice();

	protected:
	/*! List of all group of entities registered to the postoffice. */
	static std::map<std::string, std::list<Entity*> > groups__;
	/*! Registers an entity to a group. If an entity is a member of a group, it will receive all messages for this group. Group must not be "". Such a group does not exist. A group named " " may exist. */
	static void RegisterGroup(Entity* entity, const std::string& group);
	/*! Unregisters an entity from all groups. */
	static void UnregisterAllGroups(Entity* entity);
	/*! Unregisters an entity from a group. if group == "", then remove from all groups. */
	static void UnregisterGroup(Entity* entity, const std::string& group);

	/*! Send a message to all entities registered to a group. Returns true if at least one entity received the message. */
	static bool DispatchMessage(Entity * emitter, const std::string& group, const std::string& message);

	/*! Send a message with extradata to all entities registered to a group. Returns true if at least one entity received the message. */
	static bool DispatchMessage(Entity * emitter, const std::string& group, const std::string& message, const std::string& extra, const irr::core::vector3df about);

	/*! Send a message to an entity. The entity must be registered in Map::entities__ map association. Returns true if the entity received the message (which should always be the case if it exists and is properly registered in Map). */
	static bool DispatchMessage(Entity * emitter, Entity* receiver, const std::string& message);
	/*! Send a message with extradata */
	static bool DispatchMessage(Entity * emitter, Entity* receiver, const std::string& message,const std::string& extra);
	/*! Send a message with extradata and a location */
	static bool DispatchMessage(Entity * emitter, Entity* receiver, const std::string& message,const std::string& extra, const irr::core::vector3df about);
};

typedef PostOffice LaPoste; // on à tous à y gagner

#include "Entity.h"
#include "Map.h"

#endif

